Repository Management
Repository Management nima?โ
Repository Management - bu Git repositorylaringizni tartibli, xavfsiz va samarali tarzda boshqarishdir.
Bu xuddi kutubxonani tartibda saqlash kabi - har bir kitob o'z joyida, topish oson, tartib-qoidalar bor! ๐
Repository Structureโ
1. Standard Project Structureโ
my-project/
โโโ .github/ # GitHub specific files
โ โโโ workflows/ # CI/CD workflows
โ โโโ ISSUE_TEMPLATE/ # Issue templates
โ โโโ PULL_REQUEST_TEMPLATE.md
โโโ .gitlab/ # GitLab specific
โ โโโ merge_request_templates/
โโโ docs/ # Documentation
โ โโโ README.md
โ โโโ API.md
โ โโโ DEPLOYMENT.md
โโโ src/ # Source code
โ โโโ components/
โ โโโ services/
โ โโโ utils/
โโโ tests/ # Test files
โ โโโ unit/
โ โโโ integration/
โ โโโ e2e/
โโโ docker/ # Docker files
โ โโโ Dockerfile
โ โโโ docker-compose.yml
โ โโโ .dockerignore
โโโ k8s/ # Kubernetes manifests
โ โโโ deployment.yaml
โ โโโ service.yaml
โ โโโ ingress.yaml
โโโ scripts/ # Build/deployment scripts
โ โโโ build.sh
โ โโโ deploy.sh
โ โโโ test.sh
โโโ .gitignore # Git ignore rules
โโโ .env.example # Environment template
โโโ package.json # Dependencies (Node.js)
โโโ requirements.txt # Dependencies (Python)
โโโ README.md # Project documentation
โโโ LICENSE # License file
โโโ CHANGELOG.md # Version history
2. Monorepo Structureโ
company-monorepo/
โโโ apps/ # Applications
โ โโโ web-app/
โ โโโ mobile-app/
โ โโโ admin-panel/
โโโ packages/ # Shared packages
โ โโโ ui-components/
โ โโโ utils/
โ โโโ api-client/
โโโ services/ # Microservices
โ โโโ user-service/
โ โโโ payment-service/
โ โโโ notification-service/
โโโ infrastructure/ # DevOps files
โ โโโ terraform/
โ โโโ ansible/
โ โโโ k8s/
โโโ tools/ # Development tools
โโโ linting/
โโโ testing/
โโโ ci-cd/
Repository Configurationโ
1. Git Configurationโ
Global config:โ
# User information
git config --global user.name "Sizning Ismingiz"
git config --global user.email "email@company.com"
# Editor
git config --global core.editor "code --wait"
# Default branch
git config --global init.defaultBranch main
# Helpful aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
git config --global alias.visual "!gitk"
Repository config:โ
# Local repository settings
git config user.email "work@company.com"
git config core.autocrlf false
git config core.filemode false
2. .gitignore Configurationโ
Node.js project:โ
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs
lib-cov
# Coverage directory used by tools like istanbul
coverage/
*.lcov
# nyc test coverage
.nyc_output
# Dependency directories
jspm_packages/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env.local
.env.production
# Build outputs
dist/
build/
# IDE files
.vscode/
.idea/
*.swp
*.swo
*~
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Python project:โ
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Virtual environments
venv/
ENV/
env/
.venv/
# IDE
.vscode/
.idea/
*.swp
*.swo
# Environment variables
.env
.env.local
.env.production
3. Git Hooksโ
Pre-commit hook:โ
#!/bin/sh
# .git/hooks/pre-commit
echo "๐ Running pre-commit checks..."
# Check for debugging statements
if grep -r "console.log\|debugger\|pdb.set_trace" src/; then
echo "โ Debug statements found. Please remove them."
exit 1
fi
# Run linting
echo "๐งน Running linter..."
npm run lint
if [ $? -ne 0 ]; then
echo "โ Linting failed. Please fix the issues."
exit 1
fi
# Run tests
echo "๐งช Running tests..."
npm test
if [ $? -ne 0 ]; then
echo "โ Tests failed. Please fix the tests."
exit 1
fi
echo "โ
All pre-commit checks passed!"
exit 0
Commit-msg hook:โ
#!/bin/sh
# .git/hooks/commit-msg
# Check commit message format
commit_regex='^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .{1,50}'
if ! grep -qE "$commit_regex" "$1"; then
echo "โ Invalid commit message format!"
echo "Format: type(scope): description"
echo "Example: feat(auth): add login functionality"
echo ""
echo "Types: feat, fix, docs, style, refactor, test, chore"
exit 1
fi
echo "โ
Commit message format is valid!"
Access Control va Permissionsโ
1. GitHub Repository Settingsโ
Collaborators management:โ
# .github/settings.yml
repository:
name: my-project
description: Project description
homepage: https://example.com
topics: [javascript, react, nodejs]
private: false
# Features
has_issues: true
has_projects: true
has_wiki: false
has_downloads: true
# Settings
default_branch: main
allow_squash_merge: true
allow_merge_commit: false
allow_rebase_merge: true
delete_branch_on_merge: true
# Branch protection
branches:
- name: main
protection:
required_status_checks:
strict: true
contexts: [ci/tests, ci/build]
enforce_admins: true
required_pull_request_reviews:
required_approving_review_count: 2
dismiss_stale_reviews: true
require_code_owner_reviews: true
restrictions:
users: []
teams: [team-leads]
Teams va permissions:โ
# Team structure
teams:
- name: backend-team
permission: push
members:
- dev1
- dev2
- name: frontend-team
permission: push
members:
- dev3
- dev4
- name: devops-team
permission: admin
members:
- devops1
- devops2
2. CODEOWNERS Fileโ
# .github/CODEOWNERS
# Global owners
* @team-leads @senior-developers
# Frontend
/frontend/ @frontend-team
*.js @frontend-team
*.vue @frontend-team
*.css @ui-designers
# Backend
/backend/ @backend-team
*.py @backend-team
*.go @backend-team
# DevOps
/docker/ @devops-team
/k8s/ @devops-team
/.github/workflows/ @devops-team
/terraform/ @infra-team
# Documentation
/docs/ @tech-writers @team-leads
README.md @team-leads
# Configuration
*.json @backend-team @devops-team
*.yaml @devops-team
*.yml @devops-team
# Database
/migrations/ @database-team @backend-team
*.sql @database-team
Repository Templatesโ
1. GitHub Template Repositoryโ
Template yaratish:
# Template repository settings
Settings โ Template repository โ
# Template structure
template-repo/
โโโ .github/
โ โโโ workflows/
โ โ โโโ ci.yml
โ โ โโโ cd.yml
โ โโโ ISSUE_TEMPLATE/
โ โ โโโ bug_report.md
โ โ โโโ feature_request.md
โ โโโ PULL_REQUEST_TEMPLATE.md
โโโ src/
โโโ tests/
โโโ .gitignore
โโโ README.md
โโโ package.json
2. Issue Templatesโ
<!-- .github/ISSUE_TEMPLATE/bug_report.md -->
---
name: Bug Report
about: Create a report to help us improve
title: '[BUG] '
labels: bug
assignees: ''
---
## ๐ Bug Description
A clear description of what the bug is.
## ๐ Steps to Reproduce
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
## โ
Expected Behavior
What you expected to happen.
## โ Actual Behavior
What actually happened.
## ๐ฑ Environment
- OS: [e.g. macOS, Windows, Linux]
- Browser: [e.g. Chrome, Safari]
- Version: [e.g. 22]
## ๐ Additional Context
Add any other context about the problem here.
3. Pull Request Templateโ
<!-- .github/PULL_REQUEST_TEMPLATE.md -->
## ๐ Description
Brief description of changes made.
## ๐ Related Issue
Fixes #(issue number)
## ๐งช Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
## ๐ Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No breaking changes
- [ ] Tests added/updated
## ๐ธ Screenshots (if applicable)
Add screenshots here.
## ๐ Deployment Notes
Any special deployment considerations.
Repository Maintenanceโ
1. Regular Cleanupโ
Delete merged branches:โ
# Local branches cleanup
git branch --merged main | grep -v main | xargs -n 1 git branch -d
# Remote branches cleanup
git remote prune origin
# Delete local tracking branches
git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D
Large files cleanup:โ
# Find large files
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
tail -10
# Remove large files from history
git filter-branch --tree-filter 'rm -f large-file.zip' HEAD
git push origin --force --all
2. Archive Strategyโ
# Repository lifecycle
active: 2 years
maintenance: 1 year
archived: indefinite
# Archive checklist:
- [ ] Final documentation update
- [ ] Dependencies security scan
- [ ] Backup important data
- [ ] Update README with archive notice
- [ ] Set repository to read-only
3. Backup Strategyโ
# Automated backup script
#!/bin/bash
BACKUP_DIR="/backups/git-repos/$(date +%Y-%m-%d)"
mkdir -p "$BACKUP_DIR"
# Clone with all branches and tags
git clone --mirror git@github.com:company/repo.git "$BACKUP_DIR/repo.git"
# Backup issues and PRs (GitHub API)
curl -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/company/repo/issues?state=all" \
> "$BACKUP_DIR/issues.json"
# Compress backup
tar -czf "$BACKUP_DIR.tar.gz" "$BACKUP_DIR"
Repository Analyticsโ
1. Metrics Trackingโ
# Commit frequency
git log --oneline --since="1 month ago" | wc -l
# Contributors
git shortlog -sn --since="1 month ago"
# Code churn
git log --stat --since="1 month ago" | grep "file changed" |
awk '{added+=$4; deleted+=$6} END {print "Added: " added " Deleted: " deleted}'
# Most active files
git log --name-only --pretty=format: | sort | uniq -c | sort -nr | head -10
2. Health Monitoringโ
# Repository health checks
health_check:
- recent_commits: true
- active_contributors: > 2
- test_coverage: > 80%
- security_vulnerabilities: 0
- outdated_dependencies: < 5
- documentation_updated: < 30_days
Multi-Repository Managementโ
1. Git Submodulesโ
# Add submodule
git submodule add https://github.com/company/shared-lib.git lib/shared
# Initialize submodules
git submodule init
git submodule update
# Update submodules
git submodule update --remote
# Clone with submodules
git clone --recursive https://github.com/company/main-project.git
2. Git Subtreesโ
# Add subtree
git subtree add --prefix=lib/shared https://github.com/company/shared-lib.git main
# Update subtree
git subtree pull --prefix=lib/shared https://github.com/company/shared-lib.git main
# Push changes back
git subtree push --prefix=lib/shared https://github.com/company/shared-lib.git main
3. Monorepo Toolsโ
// lerna.json
{
"version": "independent",
"npmClient": "npm",
"command": {
"publish": {
"conventionalCommits": true
},
"bootstrap": {
"ignore": "component-*",
"npmClientArgs": ["--no-package-lock"]
}
},
"packages": ["packages/*"]
}
Best Practicesโ
1. Securityโ
- โ Repository secrets scan qiling
- โ Branch protection rules o'rnating
- โ 2FA enable qiling
- โ Access permissions regularly review qiling
- โ Sensitive data ni environment variables da saqlang
2. Organizationโ
- โ Consistent naming conventions ishlatang
- โ Clear documentation yozing
- โ Regular cleanup qiling
- โ Archive old repositories
- โ Template repository yarating
3. DevOps Integrationโ
- โ CI/CD pipeline sozlang
- โ Automated testing qo'shing
- โ Quality gates o'rnating
- โ Monitoring va alerting sozlang
- โ Backup strategy implement qiling
Xulosaโ
Repository Management - bu dasturlash loyihasining poydevoridir:
โ
Organization - tartibli tuzilish
โ
Security - xavfsiz access control
โ
Collaboration - samarali hamkorlik
โ
Maintenance - doimiy parvarish
โ
Automation - avtomatik jarayonlar
DevOps engineer sifatida repository managementni yaxshilash orqali butun development lifecycle ni optimize qilishingiz va jamoangizning productivligini oshirishingiz mumkin!